<template>
<el-form ref="applyForm" :model="applyForm">
  <el-form-item label="项目名称" prop="xmid" v-if="applyForm.hasOwnProperty('xmid')">
    <el-select v-model="applyForm.xmid" class="w300" @change="getProjectBaseInfo">
      <el-option :label="item.name" v-for="item in applyList" :key="item.id" :value="item.id"></el-option>
    </el-select>
  </el-form-item>

  <el-row type="flex" v-if="applyForm.hasOwnProperty('xmid')">
    <el-col :span="6">
      <el-form-item label="项目编号" prop="batch_id">
        <el-input v-model="applyForm.batch_id" disabled placeholder="尚未选择项目" class="w300"></el-input>
      </el-form-item>
    </el-col>
    <el-col :span="6">
      <el-form-item label="执行单位" prop="company">
        <el-input v-model="applyForm.company" disabled placeholder="尚未选择项目" class="w300"></el-input>
      </el-form-item>
    </el-col>
    <el-col :span="3">
      <el-form-item prop="dept">
        <el-input v-model="applyForm.dept" disabled placeholder="尚未选择项目" style="width: 150px;"></el-input>
      </el-form-item>
    </el-col>
  </el-row>

  <el-row type="flex" v-if="applyForm.hasOwnProperty('xmid')">
    <el-col :span="6">
      <el-form-item label="客户名称" prop="ticketName">
        <el-input v-model="applyForm.ticketName" disabled placeholder="尚未选择项目" class="w300"></el-input>
      </el-form-item>
    </el-col>
    <el-col :span='6'>
      <el-form-item label="立项时间" prop="created_at">
        <el-input v-model="applyForm.created_at" disabled placeholder="尚未选择项目" class="w300"></el-input>
      </el-form-item>
    </el-col>
  </el-row>

  <slot name="apply-1"></slot>

  <el-row>
    <el-col :span="15">
      <el-form-item label="附件">
        <uploadFile :params="fileParams" @test="changeFile"></uploadFile>
      </el-form-item>
    </el-col>
  </el-row>


  <el-form-item label="备注" prop="desc">
    <el-input v-model="applyForm.desc" type="textarea" maxlength="1500" show-word-limit :row="2" style="width:60%;"></el-input>
  </el-form-item>

  <el-form-item>
    <el-button type="primary" @click="addAdmin(0)">立即提交</el-button>
    <el-button type="primary" @click="addAdmin(1)">保存</el-button>
    <el-button @click="resetForm">取消</el-button>
  </el-form-item>
</el-form>
</template>

<script>
  import uploadFile from "../../common/uploadFile";
  import {mapState} from 'vuex'
  import {getProjectBase} from '@/apilist/Project'
  import {addAdminWork} from "@/apilist/Admin"
    export default {
        name: "applyCommon",
        data(){
            return {
                project_list: [
                    {id:0,name:'无'},
                ],
                fileParams: {
                    dir: 'admin',
                },
                files: [],
            }
        },
        computed: {
            ...mapState("AdminData",["applyList"]),
        },
        props: ['applyForm'],
        components: {uploadFile},
        methods: {
            changeFile(fileList){
                this.files = fileList
            },
            addAdmin(is_save){
                this.applyForm['is_save'] = is_save
                this.applyForm['fileList'] = this.files
                console.log(this.applyForm)
                //return;
                addAdminWork(this.applyForm).then(res => {
                    this.$message({
                        type: 'success',
                        message: res.msg,
                        onClose: ()=> {
                            this.resetForm();
                        }
                    });
                });


            },
            resetForm(){
                this.$refs['applyForm'].resetFields();
            },
            //获取项目基本信息
            getProjectBaseInfo(){
                getProjectBase({id: this.applyForm.xmid}).then(res => {
                    const {data} = res
                    this.applyForm.batch_id = data.batch_id
                    this.applyForm.company = data.company
                    this.applyForm.dept = data.dept
                    this.applyForm.ticketName = data.partner_id
                    this.applyForm.created_at = data.created_at
                })
            }
        },
    }
</script>

<style scoped>
.w300{width:300px;}
</style>
